<template>
<div v-if="notFound">	
	<div v-show="loadingShow">
		<loading></loading>
	</div> 
	<div v-else>

		<router-view></router-view>

		<div id="submitbox">
			 <!--class="bgf"-->
			<div class="bgf" style="background: none;">
				
				<!--服务车辆-->

				<div v-if="carRelation" style="background: #fff;" :class="{dispaly_none: !carRelation}">
					<!--车辆选择信息 start-->
					<dl class="normal-bg-t border-bottom-line">
						<dd class="server-car"><span class="server-warp"> <span class="title-ellipsis">服务车辆：</span> <i class="ellipsis">{{initData.carModelInfo.carName}}</i></span></dd>
					<!--车辆选择信息 end-->
					</dl>





					<!--车辆车牌 start-->
					<dl class="normal-bg-t border-bottom-line">
						<dd class="server-car">
							<span class="title-ellipsis">车牌号码：</span>
							<span class="ellipsis">
								<span v-show="initData.carModelInfo.plates" style="display:none;">
									<span class="gray">{{initData.carModelInfo.plates}}</span>
								</span>  
								<span v-else style="display:none;">  
									<!-- v-bind:class="{'cseclect-plate-btn':!initData.carModelInfo.plates}"   -->
									<span class="seclect-plate-btn"  v-link="{path:'/orderservice/ordercarplate',query:{name:carPlate,type:plateType,pathfrom:'confirm-order-service',skuCodes:this.$route.query.skuCodes}}">{{carPlate}}</span>
									<input class="plate-text" type="text" v-model="palteText" @blur="savePlate($event) | debounce 200" @keyup.enter="savePlate($event) | debounce 300" @keyup.32="savePlate($event) | debounce 300"  @input="savePlate($event) | debounce 300" style="text-transform : uppercase;" maxlength="7" placeholder="输入车牌号" />
								</span>
							</span>


						</dd>



						
						<dd v-show="initData.carModelInfo.plates" style="display:none;">
							<span class="gray">{{initData.carModelInfo.plates}}</span>
						</dd>  
						<dd v-else style="display:none;">  <!-- v-bind:class="{'cseclect-plate-btn':!initData.carModelInfo.plates}"   -->
							<span class="seclect-plate-btn"  v-link="{path:'/orderservice/ordercarplate',query:{name:carPlate,type:plateType,pathfrom:'confirm-order-service',skuCodes:this.$route.query.skuCodes}}">{{carPlate}}</span>
							<input class="plate-text" type="text" v-model="palteText" @blur="savePlate($event) | debounce 200" @keyup.enter="savePlate($event) | debounce 300" @keyup.32="savePlate($event) | debounce 300"  @input="savePlate($event) | debounce 300" style="text-transform : uppercase;" maxlength="7" placeholder="输入车牌号" />
						</dd>




					</dl>
					<!--车辆车牌 end-->
				</div>
				<!--end 服务车辆-->

				<!--联系人-->
				<confirm-order-custom :custname.sync="initData.userInfo.name" :mobilephone="initData.userInfo.phone"></confirm-order-custom>
				<!-- end 联系人 -->

				<!--服务门店-->
				<confirm-order-store :storeinfo='storeName'></confirm-order-store>
				<!--end 服务门店-->
				
				<!--时间组件-->
				<div style="background: #fff;">
					<confirm-order-picktime :choose-time="chooseTime"></confirm-order-picktime>
				</div>
				<!--end 时间组件-->

			</div>

			<!--在线支付项-->
			<ul id="onlinepay" v-if="payOnline.length>0" class="normal-bg">
				
				<!--固定价格-->
				<li>
					<h3>在线支付项</h3>
					<p v-for='item in payOnline' :class="{'c-red': item.prmtShortName}">
						<span><em class="blue-new">{{item.skuName}}</em> <em v-if="item.prmtShortName">({{item.prmtShortName}})</em></span>
						<span><i :class="{ 'c-red': item.prmtShortName}">¥ </i>{{item.cashPrice.toFixed(2)}} </span>
					</p>
					<!--<p v-for="item in orderMdseList">
						<span>{{item.skuName}}</span>
						<span>赠送</span>
					</p>-->
				</li>
				<!--end 非固定价格-->

				<li>
					<div class="amount">总计<span class="num"><small>¥</small>{{{totalPrice == 0 ? '0' : totalPrice.toFixed(2) | dollarPrice}}}</span></div>
				</li>
			</ul>

			<!--end 在线支付项-->

			<!--到店支付项-->
			<ul  v-if="payOnStore.length>0" class="normal-bg no-pd-r mt16">
				<li>
					<h3>到店支付项 </h3>
					<p v-for='item in payOnStore'>
						<span>{{item.skuName}}</span>
						<span><i v-if="item.cashPrice != '到店议价'">¥</i>{{item.cashPrice}}</span>
					</p>
				</li>
				<li>
					<div class="amount"><span class="gray">以上项目需要到店支付，价格仅供参考</span></div>
				</li>
			</ul>
			<!--end 到店支付项-->

			<!-- 满赠 满送 -->
			<ul  v-if="orderCouponList.length>0" class="normal-bg mt16 normal-padding">
				<li>
					<h4 class="clearfix">
			    		<span>赠送 </span>
			    		<strong class="index-service-give">&nbsp;&nbsp;<em v-for='(key, item) in orderCouponList'>{{item.pondName}}<em v-if="item.singleCount > 1">({{item.singleCount}}张)</em> <small v-if="key < orderCouponList.length-1">,</small>  </em><em>,订单结算后发放</em></strong>
			 		</h4>
				</li>
			</ul>
			<!--end 满赠 满送-->

			<!--优惠券  v-if="isapp"-->
			<a href="#" id="couponbox" v-link="{path:'/orderservice/orderchoosecoupon',query:{pathfrom: 'confirm-order-service'}, replace: true}" ca="P_确认订单$优惠券">
				<ul class="normal-bg mt16 mb40 couponPrice normal-padding">
					<li>
						<h4>
			      <!--在线支付 payOnline 存在的时候， 才使用券-->
			      <span>优惠券 (<em :class="{'color-f60': couponNum}">{{payOnline.length > 0 ? couponNum : 0}}</em>张可用)</span>
			      <span v-if="couponContent=='未使用' &&　couponPrice　== ''" class="gray ticket" >{{couponContent}}</span>
			      <span v-else class="ticket">
			      	<!-- <span  v-if="couponPrice">{{couponPrice}}元{{couponList.activityName}}<em class="font-family-ms">：-￥{{couponPrice}}</em></span> -->
			      	<span  v-if="couponPrice && couponPrice != '0'">{{couponContent}}<em class="font-family-ms">：-￥{{couponPrice}}</em></span>
			      	<span v-else>未使用</span>
			      </span>
			    </h4>
					</li>
				</ul>
			</a>
			<!--end 优惠券-->

			<div class="height-60"></div>

			<!--pay-confirm-->	
			<div class="pay-confirm" id="pay-confirm-s">
				<dl id="payConfirmOnline">
					<dt>
			        <p v-if="payOnline.length>0&&payOnStore.length<=0">
			        		<span v-if="!couponPrice">
				           		<span>在线支付<span class="red num"><small>¥</small>{{{payTotalPrice == 0 ? '0' : payTotalPrice.toFixed(2) | dollarPrice }}}</span></span>
			        		</span>
			        		<span v-else>
				           <span>在线支付<span class="red num"><small>¥</small>{{{payTotalPrice > 0 ? payTotalPrice.toFixed(2) : '0'  | dollarPrice}}}</span></span>                        
			        		</span>
			        </p>
			        <p v-if="payOnline.length>0&&payOnStore.length>0">
			           <span v-if="!couponPrice">
				           <span>在线支付<span class="red num"><small>¥</small>{{{payTotalPrice  == 0 ? '0' : payTotalPrice.toFixed(2) | dollarPrice }}}</span></span>                        
			        		</span>
			        		<span v-else>
				            <span>在线支付<span class="red num"><small>¥</small>{{{payTotalPrice > 0 ? payTotalPrice.toFixed(2) : '0' | dollarPrice}}}</span></span>                        
			        		</span>
			         <br/>
			           <span class="gray s">其他项目需到店支付</span>
			            
			        </p>
			        <p v-if="payOnline.length<=0&&payOnStore.length>0">
			          <span class="gray">以上项目需到店支付</span>
			        </p>
			      </dt>
					<dd>
						<input type="button" value="提交订单" class="ui-btn" @click="confirm | debounce 500" ca="P_确认订单$提交订单">
					</dd>
				</dl>
			</div>

			<!--end pay-confirm-->

		</div>


	</div>
</div>	
</template>

<script>

import confirmOrderCarplate from './confirm-order-carplate';
import confirmOrderCustom from './confirm-order-custom';
import confirmOrderStore from './confirm-order-store';
import confirmOrderPicktime from './confirm-order-picktime';
import loading from '../common/loading';

import common from '../../utils/common';
  
import Vue from 'vue';
import {Toast} from 'mint-ui';

export default {
	components: {
		confirmOrderCustom, confirmOrderCarplate, confirmOrderStore, confirmOrderPicktime, loading
		/*'confirmOrderCarplate': function ( resolve, reject ) {
			require.ensure(['./confirm-order-carplate'], function ( require ) {
				resolve(require('./confirm-order-carplate'));
			}, 'confirmOrderCarplate');
		},
		'confirmOrderCustom': function ( resolve, reject ) {
			require.ensure(['./confirm-order-custom'], function ( require ) {
				resolve(require('./confirm-order-custom'));
			}, 'confirmOrderCustom');
		},
		'confirmOrderStore': function ( resolve, reject ) {
			require.ensure(['./confirm-order-store'], function ( require ) {
				resolve(require('./confirm-order-store'));
			}, 'confirmOrderStore');
		},
		'confirmOrderPicktime': function ( resolve, reject ) {
			require.ensure(['./confirm-order-picktime'], function ( require ) {
				resolve(require('./confirm-order-picktime'));
			}, 'confirmOrderPicktime');
		},
		'loading': function ( resolve, reject ) {
			require.ensure(['../common/loading'], function ( require ) {
				resolve(require('../common/loading'));
			}, 'loading');
		}*/
	},

	data() {
		return {
			skuCodeList: "", // skucodes参数
			scode: [], // s码数组
			// fullday:sessionStorage.getItem("fullday"),
			payOnline: [], // 在线付
			payOnStore: [], // 到店付
			prmName: [], // 优惠信息列表
			chooseTime: sessionStorage.getItem("fullday"), // 到店选择时间
			couponNum: 0, // 券的总数
			totalPrice: 0, // 在线支付总价格
			payTotalPrice: 0,
			isapp:false,

			couponList: [{
				"couponCode": "",
				"activityName": "",
				"useDept": null,
				"settleValue": "",
				"faceValue": null,
				"templateNo": null,
				"expiryEndDate": "",
				"servicelist": null,
				"serviceCode": null
			}],

			couponContent: sessionStorage.getItem("chooseCouponContent") ? sessionStorage.getItem("chooseCouponContent") : "未使用", // 券信息
			carPlate: sessionStorage.getItem("choosePlate") ? sessionStorage.getItem("choosePlate") : "沪", // 选择拍照值
			plateType: this.$route.query.type || "c", // 牌照类型c为汉字牌照，l为字母牌照

			initData: {
				carModelInfo: {
					carName: '',
					plates: ''
				},
				userInfo: {
					name: '',
					phone: ''
				},
				storeInfo: {
					
				}
			},

			storeName: '',
			//        recommendCode: '', // 推荐码
			storeId: '',
			palteText: sessionStorage.getItem('plates'), // 车类型

			offer: true, // 推荐码验证

			fixedPrice: '', // 非固定价格

			orderCouponList: [], // 优惠券信息
			serviceCode: '', // 优惠券使用范围 
			orderMdseList: [], // 赠品信息

			loadingShow: true, // Loading 图
			nowTime: '', // 服务器当前时间
			carRelation: true, // 强弱关联
			
			mdseOrder: '', // 商品列表
			notFound: true,  // 404效果显示处理 
			
//			active: 0,
			iframe:'',
			isIOSWechat: common.isIOSWechat(),

			chooseCouponId:"",// 券ID
			chooseCouponContent:"",//券内容
			couponPrice:"",//券价格
            servicelist:""//券的可使用范围
		}
	},
	watch: {
		"chooseTime":function(){
	//        this.initCoupon();
	    }
    },
    events:{
         "setCouponParam":function(opt){
              this.chooseCouponId = opt.chooseCouponId;
              this.chooseCouponContent = opt.chooseCouponContent;
              this.couponPrice = opt.couponPrice;
              this.servicelist = opt.servicelist;
          }
    },
    route: {
		data: function() {
			
			
			//window.ANA.reconfig('').getDate().dataProcess().send();
            common.setTitle('确认订单');  // 设置title
			this.carPlate = this.$route.query.name || sessionStorage.getItem("choosePlate") || "沪";
			this.plateType = this.$route.query.type || "c";
			this.couponContent = sessionStorage.getItem("chooseCouponContent") || "未使用"; // 券信息
			if ( this.couponNum != 0 ) {
				this.useCoupon(); // 更新优惠券使用范围
			}	   
			
			try{
				/**** 解决 优惠券button显示***/

				document.querySelector('#submitbox').style.display = 'block';

				/**** 解决 优惠券button显示***/
			}catch(e){
				//TODO handle the exception
			}
		}
    },
    	ready: function() {// 设置值
    		
    		this.isapp = common.isApp();

    		
    		 /********** 清除session中优惠券信息 **********/
	      	sessionStorage.setItem('chooseCouponContent', ''); // 优惠券 内容
	      	sessionStorage.setItem('couponPrice', ''); // 优惠券 价格
	        sessionStorage.setItem('chooseCouponId', ''); // 优惠券 ID
	        sessionStorage.setItem('availableCouponList', '');
	        sessionStorage.setItem('expiryEndDate', '');// 优惠券有效截止日期
	       /********** 清除session中优惠券信息 **********/

	        
		//	this.iframe = common.setTitleAgain('确认订单', this.iframe);	        
//	        var active = 0;
		    // 处理 Loading图
//			Vue.http.interceptors.push(function ( request, next ) {
//				
////				this.loadingShow = true;
//				next(function ( response ) {
////					this.active++;
////					active--;
//					this.$nextTick(function () {
////						this.active++;
//						if (this.active == 1) {
//					 		this.loadingShow = false;
//					 		return response;
//						}
//					});
//				});
//			});
		 	
		 	
	 	// 处理 Loading图
		Vue.http.interceptors.push(function ( request, next ) {
			next(function ( response ) {
				this.loadingShow = false;
				return response;
			});
		});
		 	
		/**
		 * getSelectedElementInfo 
		 * 商店 (storeInfo) 和 车辆 (carInfo) 和 购物车 (shoppingCart)
		 */
          var _this = this;
          
          this.$http.post(common.isdev()+'/spu/getSelectedElementInfo.htm',{targetJumpUrl:window.location.href}).then(function( d ){
	          var res = typeof d.data === 'object' ? d.data : JSON.parse(d.data);
//	          res = this.cloneData(res);
	          if (res.result === 1) {
	          	
	          	var productList = res.obj.shoppingCart.productList;
		          var _skus = [];
		          if ( productList ) {
			          for (var i=0; i<productList.length; i++) {
			          	
			            _skus.push(productList[i].code);
			             
			          }
		          } else {	
		          	
		          	var __skuCode = JSON.parse(decodeURI(this.$route.query.skuCodes));
		          	_skus.push(__skuCode);

		          }
		          
				  // sku storeId
		          _this.skuCodeList = _skus;
		          try{
			          _this.storeId = res.obj.storeInfo.storeId;
		          }catch(e){
		          	//TODO handle the exception
		          }
		          
		          // 门店和车辆
		           _this.initData.carModelInfo = res.obj.carInfo || '';
		           _this.initData.storeInfo = res.obj.storeInfo || '';


		           this.carPlate = this.$route.query.name || sessionStorage.getItem("choosePlate") || common.getPlate(res.obj.storeInfo.provinceId);

		           
		          
		          
//		          this.active += 2;
		          /**
		           * 订单初始化
		           */
		          _this.$http.post(common.isdev()+'/orderPageInit/init.htm', {
		            skus: JSON.stringify(_this.skuCodeList),
		            storeId: _this.storeId
		          }).then(function( d ) {
		            var res = typeof d.data === 'object' ? d.data : JSON.parse(d.data); 
		            
//		            res = this.cloneData(res);
		            if ( res.result === 1 ) {
		            	
			            // 获取服务器当前时间
	                this.nowTime=res.obj.currentTime;
	                this.$broadcast('sendTime', [this.nowTime,""]);
		              
		              // 用户信息
		              _this.initData.userInfo = res.obj.userInfo || '';
		              _this.storeName = res.obj.storeInfo.storeName || '';
		              //初始化姓名session
		              if(_this.initData.userInfo.name){
		              	sessionStorage.setItem('username', _this.initData.userInfo.name);
		              }else{
		              	sessionStorage.removeItem('username');
		              }		              
		              
		              var payOnline = [], payOnStore = [], prmName = [], totalPrice = 0, payTotalPrice=0, scode = [];
		              var obj = res.obj;
		              var isOnline = false;
		              
		              // orderCouponList 赠送 
		              if ( obj.orderCouponList ) {
		              	var arrGift = obj.orderCouponList;
		              	 for (var i = 0; i < arrGift.length - 1; i++) {
					        var item = arrGift[i];
					        for(var j = i+1; j < arrGift.length; j++ ) {
					            if(item.pondCode === arrGift[j].pondCode){
					            	var singleCount = arrGift[i].singleCount+arrGift[j].singleCount;
					            	arrGift.splice(j, 1);
					            	j--;
					            	arrGift[j].singleCount = singleCount;
					            };
					        }
					    };
		              	this.orderCouponList = arrGift;
		              }
		              // orderMdseList 赠品信息
//		              if ( obj.orderMdseList ) {
//		              	this.orderMdseList = obj.orderMdseList;
//		              }
		              
		              
		              // 处理价格
		              if ( obj.mdseOrder && obj.mdseOrder != 'null' ) {
		              	var flagArr=[];
		              	
		              	this.mdseOrder = obj.mdseOrder; // 设置查询商品
		              	
		                for ( var i = 0; i < obj.mdseOrder.length; i++ ) {
				                if(String(obj.mdseOrder[i]['carRelation'])!='0'){
				                	// 车辆是否必须 // 强弱关联，    0（无关联） 1（弱关联） 2 （强关联）
									flagArr[i] = true;
				                }else{
				                	flagArr[i] = false;
				                }
							
				                if ( obj.mdseOrder[i].prmName ) {
				                   prmName.push(obj.mdseOrder[i].prmName);
				                }
				                
				                if ( obj.mdseOrder[i].serviceNo ) {
				                   scode.push(obj.mdseOrder[i].serviceNo);
				                }
				                
					            /**********   修改组合商品都是到在线支付   **********/
					             	if ( obj.mdseOrder[i].isConbine == 2 ) {
					             		obj.mdseOrder[i].payStaus = 0;
					             	}
					            /**********   修改组合商品都是到在线支付   **********/
					             
				                // payStatus:0-在线支付,1-到店支付
				                // fixedPrice:0-非固定价格,1-固定价格
				                if ( obj.mdseOrder[i].payStaus == 0  ) {
			                    	var cashPrice = obj.mdseOrder[i].cashPrice || 0;
				                	
			                    	totalPrice += parseFloat(cashPrice); // 总计
			                    	payTotalPrice += parseFloat(cashPrice); // 总价
				                	
				                	payOnline.push(obj.mdseOrder[i]);
				                	isOnline = true;
				                } else {
				                	
				                	if ( obj.mdseOrder[i].fixedPrice == '0' ) {
			                			obj.mdseOrder[i].cashPrice = obj.mdseOrder[i].marketPrice ? obj.mdseOrder[i].marketPrice  + '起' : '到店议价';
				                	}
				                	
				                	payOnStore.push(obj.mdseOrder[i]);
				                }
		                }
			            // 判断赠品信息是否显示在[在线支付]或者[到店支付]
//			           
			            if ( obj.orderMdseList && obj.orderMdseList != 'null' ) {
			            	for ( var i=0; i<obj.orderMdseList.length; i++ ) {
				            	var objGift = {
				            		mdseName: obj.orderMdseList[i].skuName ? obj.orderMdseList[i].skuName : 'null',
				            		cashPrice: 0,
				            		prmtShortName: obj.orderMdseList[i].prmtShortName ? obj.orderMdseList[i].prmtShortName : 'null'
				            	};
					            if ( isOnline ) { // true 表示赠品信息显示在[在线支付]中
					            	payOnline.push(objGift);
					            } else { // 赠品信息显示在[到店支付]中
					            	payOnStore.push(objGift);
					            }
					            
			            	}
			            }
			                
		                this.carRelation = flagArr.join(',').indexOf('true')>-1?true:false;
		                
		              } 
		
		              _this.scode = scode; // s码
		              _this.$set("payOnline", payOnline); // 在线支付
		              _this.$set("payOnStore", payOnStore); // 到店付款
		              _this.$set("totalPrice", totalPrice); // 筛选总价格
		              _this.$set("payTotalPrice", payTotalPrice);
		              sessionStorage.setItem('payTotalPrice', payTotalPrice);
		              _this.$set("prmName", prmName); // 满赠满送信息
		              
		              // 在线支付 才使用券
		              _this.initCoupon( _this.scode, payOnline ); // 获取券信息
		              _this.useCoupon(); // 优惠券使用范围
		              
		              
//		              this.active -= 1;
		              this.notFound = true;
		            } else if ( res.result === 0 ) {
//		            	Toast(res.message);
		            	this.notFound = false;
		            	common.goNotFound(res.errorCode);
		            }
								
					// 判断是否登陆
		            if ( res.result === -99 ) {
		              common.goLogin();
		            }
		            
		          }, function( err ) {
		            Toast(err);
		          });
	          	this.notFound = true;
	          } else if ( res.result === 0 ) {
	          	this.notFound = false;
	          	common.goNotFound(res.errorCode);
	          }
	
          }, function( err ) {
          	Toast(err);
          });
         common.ANA_Analytics();
      },
      methods: {    
      	
      		/**
      		 * 获取券信息
      		 * @param {Array} socde s码
      		 * @param {Array} payOnline 券 
      		 */
          initCoupon: function( socde, payOnline ) {
          	
            var scode = socde.join(',');
            
			/**
			 * 劵码列表页面
			 */
            this.$http.post(common.isdev()+"/orderPageInit/conponList.htm",{
            	"coupons": scode
//          	"coupons": 'S0004'
            }).then(function( d ){

               var res = typeof d.data === 'object' ? d.data : JSON.parse(d.data);

//             res = this.cloneData(res);
               
               if ( res.result === 1 ) {
               	
                  var chooseTime = new Date(this.chooseTime);
                  var availableCouponList = [];
                  
                  this.couponList = res.obj.couponList;

                  var defaultTime = new Date(sessionStorage.getItem('fullday'));
                  for ( var i =0; i<this.couponList.length; i++ ) {
                  	
                    var d = this.couponList[i].expiryEndDate.replace(/-/g,"/");
                    var time = new Date(d); // 过期时间

                     //过期时间大于当前选择时间 time.getTime() >= chooseTime.getTime() && time.getTime() >= defaultTime.getTime()
					if ( time.getTime() >= defaultTime.getTime()) {
						availableCouponList.push(this.couponList[i]);
					}
                    
                  }


                  
                  var couponLen = availableCouponList.length;
                  
                  this.$set("couponNum", couponLen);
                  if ( couponLen == 0 ) {
                  	sessionStorage.setItem('couponPrice', '');
                  }
                  
                  if ( couponLen<=0 ) {
                    this.$set("couponContent","未使用");
                  }
					
					// 在线支付 才使用券
                  if ( payOnline.length > 0 ) {
	                  sessionStorage.setItem("availableCouponList",JSON.stringify(availableCouponList));
                  }
                 
               } else if ( res.result == 0 ){
               	console.log('该用户无券');
               }
               
           		 // 判断登陆
               if ( res.result == -99 ) {
               		common.goLogin();
               }
               
            },function(){
               Toast('劵码列表接口请求出错');
            });	
       
       
          },
         
          // 提交
          confirm: function() {
          	
            var _this = this, settleList = [];
            
            this.serviceNo = localStorage.cacheSeverLocalStorage;
            
          	// 修改sku
            var skuCodeList = this.skuCodeList;

            if ( typeof skuCodeList == 'string' ) {
            	skuCodeList = JSON.parse(skuCodeList);
            	settleList = {quality:'1', skuCode: '["' + JSON.stringify(skuCodeList[0]) + '"]' };
            } else {
            	for ( var i = 0; i<skuCodeList.length; i++ ) {
	              settleList.push({quality:'1', skuCode:skuCodeList[i]});
	            }
            }
            
            // 修改日期
            var curTime = '';
            var serDay = sessionStorage.getItem("fullday");
            if ( serDay && serDay !== 'undefined' && serDay !== 'null' ) {
            	curTime = this.timestamp(serDay);
            } else {
            	curTime = this.timestamp(Date.parse(new Date()));
            }
            var _reservationDateStr = curTime.replace(/[\u4e00-\u9fa5]/g, '/');
            if ( _reservationDateStr.substring(_reservationDateStr.length - 1) === '/' ) {
            	_reservationDateStr = _reservationDateStr.substring(0, _reservationDateStr.length-1);
            }
            
            // 如果需要爱车
            if(this.carRelation){
	            // 修改车牌
	            
	             var plates = '';
	            // 验证是否填写正确车辆
	            if ( _this.initData.carModelInfo.plates ) {
	            	plates = _this.initData.carModelInfo.plates;
	            } else if( _this.palteText ) {

	                var isPlate = /^[A-Z]{1}[A-Z_0-9]{5,6}$/; // 车牌正则验证

//	                var isPlate = /^[-.A-Za-z0-9➋➌➍➎➏➐➑➒_\u4E00-\u9FA5]$/; // 车牌正则验证
	                if(!isPlate.test(_this.palteText)) {
	                    Toast("车牌格式错误！");
	                    return false;
	                }

	            	plates = _this.carPlate + _this.palteText;	
	            	
	            } else {
	            	Toast('请填写车牌');
	            	return false;
	            }
				
            }

            
            // 修改联系人
            var contactName = '';
            var _name = this.trim(sessionStorage.getItem('username'));
            if ( _name ) { // 输入联系人
            	if ( this.checkNickName(_name) ) {
	            	contactName = _name;
            	} else {
            		Toast('联系人仅限输入中英文');
            		return false;
            	}
            } else { // token 存在用户名
//          	if ( _this.initData.userInfo.name ) {
//	            	contactName = _this.initData.userInfo.name;
//          	} else {
            		Toast('请填写联系人');
            		return false;
//          	}
            }
            
            // 判断券码
            var _couponCode = sessionStorage.getItem("chooseCouponId") || '';
            if ( _couponCode == '00' ) {
            	_couponCode = '';
            }else{
            	debugger;
            	var expiryEndDate = sessionStorage.getItem("expiryEndDate").replace(/-/g,"/");
	            if( new Date(this.chooseTime).getTime() > new Date(expiryEndDate).getTime() && this.couponPrice){
	            	Toast('当前预约时间该优惠券不能使用！');
	            	return;
	            }	            	
            }



           

            
            // 提交订单数据组合
            var fedOrderVOString = {
            	// 结算订单商品VO 数量+skuCode
            	settle: settleList,

            	// 订单类型   [01,线上售卡][02,普通服务][03,轮胎服务][04,洗车服务][05,套餐卡服务][06,套餐卡用卡]</p>
            	orderCommitType: '02',

            	// 车信息
            	// carModelInVo: {carId:'001',plates:'苏HDN218',carName:'朗逸',assetId:'1'},

            	// 联系人
            	contactName: contactName,

            	// 到店日期        
            	reservationDateStr: _reservationDateStr,

            	// 上午 下午          
            	remark: sessionStorage.getItem("remark"),

            	// 券码                 
            	//            coupon: { couponCode: _couponCode },

            	// 门店信息  
            	storeInfo: _this.initData.storeInfo,

            	// 推荐码
            	//            recommendCode: recommendCode 
            };
            
            //          carModelInVo: { plates: plates },
			/********* 处理 不显示爱车 传递给后台检测 而 返回 `内部服务订单创建失败` ************/
            if (this.carRelation) {
            	fedOrderVOString.carModelInVo = { plates: plates }
            }
            // 处理券码是否存在
            if ( _couponCode ) {
            	fedOrderVOString.coupon =  { couponCode: _couponCode };
            }
            console.log(fedOrderVOString, 'fedOrderVOString');
            /**
             * 提交订单
             */
            this.$http.post(common.isdev()+'/orderFollow/orderHandle.htm', {
				fedOrderVO: JSON.stringify(fedOrderVOString)
			}).then(function(d) {
				var res = typeof d.data === 'object' ? d.data : JSON.parse(d.data);

				// 判断是否登陆
	            if ( res.result === -99 ) {
	              common.goLogin();
	              return false;
	            }
	            
				if(res.success) {
					// 判断是否跳转支付页面
					if(res.statusCode == '000009') {
						// 成功之后 不需要支付跳转路由到成功页

						window.location.href = process.env.HOST_NAME + '/service/success.htm?orderNo='+res.orderHeadCode;
					} else {

						window.location.href = res.payURL;
					}
	
				} else {
					Toast(common.queryCodeMessage(res));
				}
	
			}, function(err) {
				console.log(JSON.stringify(err) +'--订单提交出错');
            });
	            
          },
          
          /**
           * 车牌验证
           */
          savePlate: function ( event ) {
//        	var val = event.currentTarget.value;
          	var val = this.palteText ? this.palteText : '';
          	val = this.converToUpperCase(val) || '';

          	var isPlate = /^[A-Z]{1}[A-Z_0-9]{5,6}$/;
          	
          	// 大于6位截取
          	if ( val.length > 7 ) {
          		val = val.substr(0, 7);

          	}
          	// 去除中文,特殊字符,并且转换大写
          	val = this.trim(this.removeCn(val));
			
			// 验证车牌

			if ( val.length >= 6 ) {
	          	if ( !isPlate.test(val) ) {
	          		Toast('车牌格式错误');
	        	}
         	}
			

          	this.palteText = val;
          	
//        	sessionStorage.setItem(plates, val);
          },
          
           // 切换车牌
          changePlate: function ( event ) {
          	var _this = this;
			setInterval(function () {
				_this.savePlate(event);
			}, 100);
          },
          
          /**	  
           * 处理 年月日 时间
           * @param {String} time 时间格式
           * 'Tue Dec 13 2016 14:25:26 GMT+0800 (中国标准时间)'
           * '2016年12月13日'
           * '1481610386613'
           * '2016/12/14'
           * 'Wednesday, December 14, 2016'
           * @return {String} 年月日时间
           * @example 2016/11/6  
           */
          	timestamp: function ( time ) {
          		
				// 2016年12月13日
				var exp = /[年|月|日]/g;
				if ( exp.test(time) ) {
					return time;
				}
				
				// 1481610386613
				var expNum = /\d{12}/g;
				if ( expNum.test(time) ) {
					time = new Date(parseFloat(time)).toJSON();
				}
				
				var date = new Date(time);
				var Y = date.getFullYear() + '/';
				var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
				var D = date.getDate() + ' ';
		
				return Y + M + D;
		
			},
			/**
			 * 判断是否为空的对象
			 * @param {Object} obj
			 * @return {Boolean} 
			 */
			isEmptyObj: function ( obj ) {
				var num = 0;
				for ( var i in obj ) {
					num++;
				}
				return num > 0 ? true : false;
			},
			
			/**
			 * 转换大写
			 * @param {String} str 转换的字符串
			 * @return {Mixin} Boolean String  
			 */
			converToUpperCase: function ( str ) {
				if ( str ) {
					if ( !str && str == 'undefined' && str == 'null' ) {
						return false;
					}
					
					var first = str.toUpperCase();
					
					return first;
				}
			},
			
			/**
			 * 使用优惠券 范围
			 */
			useCoupon: function () {
				
				// 订单确认页总价格(在线支付总金额,包括不使用券的商品金额)
	        	var payTotalPrice = parseFloat(sessionStorage.getItem('payTotalPrice'));
	        	
		        try{
		        	var _scode = this.scode; // 订单确认页所有商品的S码
		        	var _mdseOrder = this.mdseOrder; // 订单确认页所有在线支付商品列表
		        	var mdseCouPrice = 0; 
					var servicelist = JSON.parse(sessionStorage.getItem('servicelist')); // 优惠券可匹配的S码
					
					// 是否存在券
					if ( this.couponNum != 0 ) {
						// 优惠券使用 S码
						for ( var i=0; i<servicelist.length; ++i ) {
							// _mdseOrder 商品s码
				        	for ( var j=0; j<_mdseOrder.length; ++j ) {
				        		if(servicelist[i].serviceCode == _mdseOrder[j].serviceNo && _mdseOrder[j].fixedPrice == 1) {
				        			mdseCouPrice += parseFloat(_mdseOrder[j].cashPrice);
				        			break;
				        		}
				        	}
				        }

						// 获取选择券的金额 和 内容
						this.couponPrice = sessionStorage.getItem('couponPrice')||0; // 更新优惠券
				        this.couponContent = sessionStorage.getItem('chooseCouponContent')||''; // 更新内容
				        
				        // 确定使用  券金额 还是  商品金额
				        if(this.couponPrice >= mdseCouPrice) {
				        	payTotalPrice = payTotalPrice - mdseCouPrice; // 在线支付金额
				        } else {
				        	payTotalPrice = payTotalPrice - this.couponPrice; // 在线支付金额
				        }
				        
						// 总金额 - 商品总金额		
						// 设置价格
						this.$set('payTotalPrice', payTotalPrice);
					}
					
		        }catch(e){
		        	this.$set('payTotalPrice', payTotalPrice);
		        	this.couponPrice = '';  // 没有返回 serviceCode
		        }
			}, 
			
			/**
			 * 验证用户名
			 * @param {Object} nickName 当前用户名
			 * @return {Boolean} 是否用户名验证成功
			 * 
			 * 规则： 限16个字符，支持中英文、数字、减号或下划线
			 */
			checkNickName: function ( nickName ) {
				var regStr = /^[\u4e00-\u9fa5_a-zA-Z0-9-]{1,16}$/g;
				
				if ( !nickName ) {
					return false; 
				}
				
				return regStr.test(nickName);
			},
			/**
	         *  去除前后空格
	         * @param {String} str
	         * @reutrn {String} 
	         */
	        trim: function ( str ) {
	        	if ( str ) {
				    return str.replace(/(^\s*)|(\s*$)/g, "");
	        	}
	        	return '';
			},
			
			/**
			 * 去除返回数据 为 `null`
			 * @param {Object} 需要去除返回数据中的null的对象
			 * @return {Object} 深拷贝或者浅拷贝 处理后的对象 
			 */
			cloneData: function ( obj ) {
				var str, newObj = {};
				if ( typeof obj !== 'object' ) {
					return ;
				} else {
					for ( var i in obj ) {
						newObj[i] = typeof obj[i] === 'object' ? this.cloneData(obj[i]) : obj[i];
					}
				}
				return newObj;
			},
			
			/**
			 * 去除字符串中的中文
			 * @param {String} str 需要的字符串
			 * @return {String} 去除中文和特殊字符串
			 */
			removeCn: function( str ) {
				var rep = /[\u4E00-\u9FA5]|[!+|@+|#+|$+|%+|^+|&+|*+|(+|)+|,+|.+|>+|<+|/+|?+|~+|`+|,+|.+|<+|>+|/+|?+]/g;
				return str && str.replace(rep, '').toUpperCase();
			}
			
      },
		  events: {
		    'chooseTime-dispatch'() {
				this.chooseTime = sessionStorage.getItem("fullday");
				var expiryEndDate = sessionStorage.getItem("expiryEndDate").replace(/-/g,"/");
				// 在线支付 才使用券
				this.initCoupon( this.scode, this.payOnline ); // 获取券信息
				 // 优惠券使用范围

				if ( new Date(expiryEndDate).getTime() < new Date(this.chooseTime).getTime() ) {
					this.couponContent = "未使用";
					sessionStorage.setItem("couponPrice",'');
					sessionStorage.setItem("chooseCouponId",'');
				}

				this.useCoupon();
		    }
		  }
	}

</script>

<style lang="scss">

	@import '../../assets/css/_functions.scss';
	@import '../../assets/css/_variables.scss';
	.gray{
		color:#8392A0;
	}
	.dispaly_none {
		display: none;
	}
	
	.bgf{
		// margin-top: rem(16);
	}
	.c-red {
		color: $_price;	
	}
	.height-60 {
		height: rem(80);
	}
	.index-service-give {
		font-weight: normal;
	}
	.server-warp {
		width: 100%;
		display: inline-block;


	}
	.title-ellipsis {
		float: left;
	}
	.ellipsis {
		/*float: left;*/
		display: inline-block;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		width: rem(260);
		text-align:right;
		color:#8392A0;
	}
	
	.color-f60 {
		color: $_price;
	}
	.line-h {
		line-height: rem(28);
	}
	.font-family-ms {
		font-family: "microsoft yahei";
	}
	.server-car {
		width: 100% !important;
	}
	.normal-bg-t {
		padding-left: 0 !important; 
	}
	.bgf {
		background-color: #fff;
		.recommend-code {
			width: 100%;
			height: rem(48);
			line-height: rem(48);
			padding-left: rem(14);
			color: $_333;
			font-size: rem(14);
			input {
				border: none;
				background: $_fff;
				padding-left: rem(5);
			}
		}
		.border-bottom-line{
			border-bottom: 1px solid #c9d5e0;
		}
	}
	.normal-bg-t {
		background-color: $_fff;
		font-size: rem(14);
	}
	.normal-bg {
		background-color: $_fff;
		padding: rem(12) 0;
		font-size: rem(14);
		margin:0 rem(20);
		border-bottom: 1px solid #c9d5e0;
	}
	.normal-padding{
		padding:rem(19) 0;
	}
	.normal-bg-t {
		clear: both;
		overflow: hidden;
		height: rem(55);
		line-height: rem(55);
		margin:0 rem(20);
		dd {
			float: left;
		}
		dd:first-child {
			display: inline-block;
			width: rem(150);
			height: rem(44);
		}
		.picktime {
			width: rem(105);
		}
		dd:last-child {
			float: right;
		}
	}
	
	ul {
		li {
			// border-bottom: 1px solid $_dedede;
			p {
				color:#243742;
				line-height: rem(30);
				font-size: rem(13);
			}
			h3 {
				line-height: rem(27);
			}
			h4 span:last-child {
				font-size: rem(13);
			}
		}
		li:first-child {
			border-bottom: 0;
		}
	}
	.couponPrice {
		color: $_666;
	}
	ul li p span:last-child,
	ul li h3 span:last-child,
	ul li h4 span:last-child {
		float: right;
	}
	
	.seclect-plate-btn {
		background: #8392A0 url(../../assets/images/arrow-b.png) no-repeat rem(20) center;
		background-size: rem(9) rem(6);
		display: inline-block;
		width: rem(30);
		height: rem(24);
		border-radius: rem(4);
		line-height: rem(24);
		color: #fff;
		padding-left: rem(4);
		text-align:left;
	}
	
	.plate-text {
		background: none;
		border: none;
		width: rem(70);
		margin-top: rem(-4);
		margin-left: rem(7);
		color: #243742;
		line-height: rem(28);
	}
	
	i {
		color:#243742;
	}
	
	.username-text {
		background: none;
		border: none;
		width: rem(96);
		margin-top: rem(-4);
		color: #243742;
	}
	
	.amount {
		height: rem(30);
		line-height: rem(30);
		text-align: right;
		padding-top: rem(5);
	}
	
	.num {
		color: $_price;
		font-size: rem(16);
	}
	
	.num small:first-child {
		margin: 0 rem(5);
	}
	
	.mb40 {
		margin-bottom: rem(80);
	}
	
	.no-pd-r {
		padding-right: 0;
	}
	
	.no-pd-r p, .no-pd-r h3 {
		padding-right: rem(15);
	}
	
	.ticket {
		background: url(../../assets/images/imgs/sf-arrow-right-1.png) no-repeat center right;
		background-size: rem(24/3) rem(39/3);
		padding-right: rem(12);
		margin-top:0.2rem;
		// max-width: 21rem;
	    height: 1.6rem;
	    overflow: hidden;
	    line-height: 1.7rem;
	}
	.phone-num {
		background: transparent url(../../assets/images/phone.png) no-repeat left center;
		padding-left: rem(15);
	}
	.pd-b8 {
		padding-bottom: rem(8);
	}
	.pay-confirm {
		width: rem(375);
		height: rem(70);
		background: #fafbfc;
		position: fixed;
		bottom: 0;
		z-index: 10;
		border-top: 1px solid $_dedede;
		overflow: hidden;
		padding:rem(12) 0;
		-webkit-box-shadow:0 0 20px rgba(204, 204, 204, .7);
		-moz-box-shadow:0 0 20px rgba(204, 204, 204, .7);
		box-shadow:0 0 20px rgba(204, 204, 204, .7);  
		dl {
			dt {
				float: left;
				font-size: rem(14);
				padding-left: 2rem;
				p {
					display: table-cell;
					height: rem(48);
					vertical-align: middle;
				}
				small:first-child {
					margin: 0 rem(5)
				}
				.s {
					font-size: rem(12);
				}
			}
			dd {
				float: right;
			}
		}
		.ui-btn {
			width: rem(148);
			height: rem(45);
			line-height: rem(45);
			border-radius: 0;
			background-color: #ff6600;
			font-size: rem(18);
			color: #fff;
			border: none;
			border-radius:rem(5);
			margin-right:rem(20);

		}
	}
	
</style>